<?php
/**
 * 毛文科
 */
namespace app\admin\controller;
use app\admin\builder\Builder;
use app\BaseController;
use think\facade\Db;
use think\Request;

class Bumber extends BaseController
{
    public function show_list(){
        $datas = [
          [
              'id'=>0,
              'name'=>'哈哈'
          ]  ,
            [
                'id'=>1,
                'name'=>'呵呵'
            ]  ,
        ];
        $field = [
            [
                'field'=>'name',
                'field_name'=>'名称'
            ]
        ];
//        Builder::form()->setProject()
        return Builder::table()
            ->setAction('mymodel/page')
            ->addToolbarDemo('alldel','全部删除1',null,'mymodel/edit')
            ->addToolbarDemo('add','添加1',null,'mymodel/del')
            ->addToolbarDemo('back','返回1',null,'mymodel/del')
            ->addToolbarDemo('text','table1',null,'mymodel/del')
            ->addToolbarDemo('search','搜索1',$field,'mymodel/del')
            ->setPage()
            ->setMonitorAction('edit','mymodel/edit')
            ->setMonitorAction('button','mymodel/edit')
//            ->addToolbarDemo('a','下载',[],'mymodel/edit')
//                ->setColumn('input','id',"ID")
//            ->setColumn('input','name','名称')
            ->setColumn('button','name','名称s','mymodel/edit')
            ->setColumn('switch','status','状态','',null,null,'',['启用','关闭'])
//            ->setColumn('switch','status','状态','',null,'center','',['开启','关不'])
            ->setRightHeader('操作')
            ->setButton('button','查看','mymodel/edit')
            ->setButton('detail','查看','mymodel/edit')
            ->setButton('edit','查看','mymodel/edit')
            ->setButton('del','查看','mymodel/edit')
            ->setButton('a','查看','mymodel/show_list')
            ->fetch();
    }
    public function page(Request $request){
        $id = $request->param('id',null);
        $limit = $request->param('limit',10);
        $dta = Db::name('index_models');
        if($id){
            $dta = $dta->where('id',$id);
        }
        $dta = $dta->paginate($limit)
            ->toArray();
        return json_page_response($dta);
    }
    public function add(){
        $data = [
          [
              'id'=>0,
              'name'=>'昨天'
          ],[
                'id'=>1,
                'name'=>'今天'
            ]
        ];
        $tree = [
            [
                "id"=>0,
                "title"=>'权限管理',
                'spread'=>true,
                'children'=>[
                    [
                        "id"=>1,
                        "title"=>'增',
                        'spread'=>true
                    ],
                    [
                        "id"=>2,
                        "title"=>'删',
                        'spread'=>true
                    ],[
                        "id"=>3,
                        "title"=>'改',
                        'spread'=>true
                    ],[
                        "id"=>4,
                        "title"=>'查',
                        'spread'=>true
                    ],
                ]
            ],
            [
                "id"=>5,
                "title"=>'数据管理',
                'spread'=>true,
                'children'=>[
                    [
                        "id"=>6,
                        "title"=>'增',
                        'spread'=>true
                    ],
                    [
                        "id"=>7,
                        "title"=>'删',
                        'spread'=>true
                    ],[
                        "id"=>8,
                        "title"=>'改',
                        'spread'=>true
                    ],[
                        "id"=>9,
                        "title"=>'查',
                        'spread'=>true
                    ],
                ]
            ],
        ];
        return Builder::form()
            ->setAction('bumber/edit')
            ->setProject('tree','tree','树结构','1,2,3',$tree)
//            ->setProject('input','input','展示框','','','哈哈哈哈哈哈哈哈')
//            ->setProject('checkbox','checkbox','多选','',$data,'',true)
//            ->setProject('editor','editor','编辑','')
//            ->setProject('file','file','文件','')
//            ->setProject('files','files','多文件','')
//            ->setProject('img','img','图片','')
//            ->setProject('imgs','imgs','多图片','')
//            ->setProject('password','password','密码','')
//            ->setProject('radio','radio','单选','',['昨天','今天'])
//            ->setProject('switch','switch','开关','',['昨天','今天'])
//            ->setProject('textarea','textarea','多行文本','',['昨天','今天'])
//            ->setProject('time','time','时间','',['昨天','今天'])
//            ->setProject('select','select','选择',null,['昨天','今天'],'',true)
            ->setButton('submit','提交')
//            ->setButton('back','返回')
            ->fetch();
    }
    public function edit(Request $request){
        $data = $request->param();
        return json_to_respos('修改成功',200,$data);
    }
}